
####
##
## Figure 2 : Civilian and Combatant Deaths
##
####

civ.nonciv.plot <- function(mydata, area, side, name2, time, lower, upper){
  pl <- ggplot(mydata, aes(x=time)) +
    sapply(mydata$date[(1:1430)[agree$agree==1]][1:15], function(xint) geom_line(linetype = "dashed", data = data.frame(x = c(xint,xint), y = c(-100, 100)), aes(x = x, y = y))) +  
    geom_line(aes(y=side, color="Non-Civilian")) +
    geom_line(aes(y=-deaths_civilians, color="Civilian")) +  ggtitle(area) +  theme_classic() + 
    scale_y_continuous(name=name2, limits=c(lower, upper), labels=c(100,50,0,50,100)) + 
    labs(x = " ", y = name2, color = " ", size=0.8)  +
    scale_color_manual(name="", values = c("Non-Civilian"="palevioletred2", "Civilian"="skyblue2", "Peace Talks" = "black")) +
    scale_shape_manual(values = c(NA, NA, NA)) + 
    theme(plot.title = element_text(size = 14, family = "LM Roman 10"),
          legend.position = "inside", legend.position.inside = c(0.85,0.85), legend.text=element_text(size=12, family = "LM Roman 10"),
          axis.text=element_text(size=10, family = "LM Roman 10"),
          axis.title=element_text(size=12, family = "LM Roman 10"))
  return(pl)
}

mecburiyet <- data.frame("position"=c(-70,-70),"date"=as.Date(civil.op.as$date[(1:367)[agree$agree==1]][1:2]-5),
                         "isim"=c("Geneva III", "Cesafire Deal"))

pl.op.as <- civ.nonciv.plot(civil.op.as[1:367,],"Government Territory",civil.op.as$deaths_a[1:367],
                            "Opposition Inflicted",time=civil.op.as$date[1:367],-100,100)
pl.op.as <- pl.op.as + geom_text(data=mecburiyet,aes(x=date, y=position, label = isim), angle=90, family="LM Roman 10",size=3)
pl.op.as

div.plotting <- function(mydata, divdata, area, time, lower, upper,y){
  ggplot(mydata, aes(x=time, y=d)) +
    geom_line() +  
    sapply(mydata$date[(1:1430)[agree$agree==1]], function(xint2) annotate("rect", xmin = xint2-15, xmax = xint2, ymin = -100, ymax = 100, alpha = .3)) +
    sapply(mydata$date[(1:1430)[agree$agree==1]], function(xint) geom_line(color="skyblue2", linetype = "dashed", data = data.frame(x = c(xint,xint), y = c(-100, 100)), aes(x = x, y = y))) +
    ggtitle(area) +  theme_classic() + 
    scale_y_continuous(name=y, limits=c(lower, upper)) + 
    labs(x = " ", y = y, color = " ", size=0.8) +
    scale_color_manual(name="", values = c("Change Point"="palevioletred2", "Meeting"="skyblue2")) +
    theme(plot.title = element_text(size = 14, family = "LM Roman 10"), 
          axis.text=element_text(size=10, family = "LM Roman 10"),
          axis.title=element_text(size=12, family = "LM Roman 10"))
}

p.op.as <- div.plotting(civil.op.as[1:367,],divisive.op.as[1:367,],"Government Territory",time=civil.op.as$date[1:367],-100,100, "Opposition-Inflicted") + theme(legend.position = "none")
B <- grid.arrange(pl.op.as,p.op.as,ncol=1)

ggsave("Civnonciv_diff2.pdf", plot = B ,width=12, height=7,units = "in")  